import preferences from '@ohos.data.preferences'
class PreferenceUtil {
  private pref: preferences.Preferences

  async loadPreference(context) {
    try {
      this.pref = await preferences.getPreferences(context, 'heimaHealthy')
      // Logger.debug()
    } catch (e) {

    }
  }

  async putPreferenceValue(key: string, value: preferences.ValueType) {
    if (!this.pref) {
      return
    }
    try {
      await this.pref.put(key, value)
      await this.pref.flush()
    } catch (e) {

    }
  }

  async getPreferenceValue(key:string, defaultValue: preferences.ValueType){
    if (!this.pref) {
      return
    }
    try {
      let value = await this.pref.get(key, defaultValue)
      return value
    } catch (e) {

    }
  }
}
export default new PreferenceUtil()